// import fire from '@/assets/images/fire.png'
import global from '@/views/Global.vue'
let get = {
    data() {
        return {
            getCoordinate: [],
        }
    },
    methods: {
        /**
         * @brief 获取鼠标点击坐标
         * @param {*} viewer 
         * @param {*} handler 
         */
        getPosition() {
            const that = this
            const viewer = global.viewer
            const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
            handler.setInputAction(function(e) {
                that.getCoordinate = []
                let ray = viewer.camera.getPickRay(e.position);
                let cartesian = viewer.scene.globe.pick(ray, viewer.scene);
                let cartographic = Cesium.Cartographic.fromCartesian(cartesian);
                let lng = Cesium.Math.toDegrees(cartographic.longitude); // 经度
                let lat = Cesium.Math.toDegrees(cartographic.latitude); // 纬度
                let alt = cartographic.height; // 高度
                that.getCoordinate.push({ lon: lng, lat: lat, alt: alt })
            }, Cesium.ScreenSpaceEventType.LEFT_CLICK)
            return that.getCoordinate
        },

        /**
         * @brief 创建火焰粒子
         * @param {Object} options position、img、viewer
         * @returns 
         */
        createParticleFire(options) {
            let position = options.position
            const viewer = options.viewer

            function computeModelMatrix(position) {
                const center = Cesium.Cartesian3.fromDegrees(position.lon, position.lat, position.alt);
                const matrix = Cesium.Transforms.eastNorthUpToFixedFrame(center);
                return matrix;
            }

            function computeEmitterModelMatrix() {
                let hpr = Cesium.HeadingPitchRoll.fromDegrees(0, 0, 0);
                let trs = new Cesium.TranslationRotationScale();
                trs.translation = Cesium.Cartesian3.fromElements(0, 0, 0);
                trs.rotation = Cesium.Quaternion.fromHeadingPitchRoll(hpr);
                let result = Cesium.Matrix4.fromTranslationRotationScale(trs);
                return result
            }

            var particle = new Cesium.ParticleSystem({
                image: require('@/assets/images/fire.png'),
                startColor: Cesium.Color.RED.withAlpha(0.1),
                endColor: Cesium.Color.YELLOW.withAlpha(0.5),
                startScale: 10,
                endScale: 5,
                minimumParticleLife: 1.5,
                maximumParticleLife: 2,
                minimumSpeed: 29,
                maximumSpeed: 30,
                imageSize: new Cesium.Cartesian2(1, 1),
                sizeInMeters: true,
                // Particles per second.
                emissionRate: 100,
                // lifetime: 60.0,
                emitter: new Cesium.CircleEmitter(10.0),
                modelMatrix: computeModelMatrix(position),
                emitterModelMatrix: computeEmitterModelMatrix()
            })
            viewer.scene.primitives.add(particle);
            // viewer.camera.setView({
            //     destination: Cesium.Cartesian3.fromDegrees(position.lon, position.lat, position.alt)
            // })
        }
    },
}
export default get